<template>
  <el-dialog
    width="60%"
    :before-close="dataFormCancle"
    :title="title"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="100px">
	<el-row>
    <el-col :span="12">
        <el-form-item label="入园时间" prop="inTime">
          <el-date-picker v-model="dataForm.inTime" style="width: 100%" type="datetime"
            placeholder="入园时间"></el-date-picker>
        </el-form-item>
    </el-col>
		<el-col :span="12">
		    <el-form-item label="出园时间" prop="outTime">
          <el-date-picker v-model="dataForm.outTime" style="width: 100%" type="datetime"
            placeholder="出园时间"></el-date-picker>
		    </el-form-item>
		</el-col>
    <el-col :span="24">
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" rows="6" v-model="dataForm.remark" placeholder="备注"></el-input>
        </el-form-item>
    </el-col>
	</el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dataFormCancle">取消</el-button>
      <el-button :loading="loading" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import {addOrUpdate} from "@/api/business/admissionrecord";
  export default {
    data () {
      return {
      	loading: false,
      	title:'',
        visible: false,
        dataForm: {
          id: 0,
          cardId: '',
          outTime: '',
          remark: '',
          inTime: '',
          createTime: ''
        },
        dataRule: {
          cardId: [
            { required: true, message: '年卡ID不能为空', trigger: 'blur' }
          ],
          outTime: [
            { required: false, message: '出园时间不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: false, message: '备注不能为空', trigger: 'blur' }
          ],
          inTime: [
            { required: true, message: '入园时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (record) {
        this.visible=true
        this.dataForm=record
        if(this.dataForm&&this.dataForm.id){
          this.title='进出园记录'+'修改'
        }else{
          this.title='进出园记录'+"新增"
        }
      },
      //关闭表单
      dataFormCancle() {
        this.visible = false
        this.loading = false
        this.$emit('refreshDataList')
      },
      // 表单提交
      dataFormSubmit () {
      	this.loading = true;
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
				addOrUpdate(this.dataForm).then(res=>{
					this.visible = false
	          this.loading = false
				    this.$modal.msgSuccess(this.title+"成功");
            		this.$emit('refreshDataList')
				}).catch(res => {
	              let _this = this
	              setTimeout(() => {
	                _this.loading = false
	              }, 2000)
	            })
          }else {
            this.loading = false
          }
        })
      }
    }
  }
</script>
